package pl.gigiel.behaviour.steermanager.factory;

import java.lang.reflect.Constructor;

import pl.gigiel.behaviour.ISteerManager;
import pl.gigiel.behaviour.ISteerManagerFactory;
import pl.gigiel.behaviour.exception.BehaviourException;


public class SteerManagerFactory implements ISteerManagerFactory {
	private static ISteerManagerFactory steerManagerFactory;

	private SteerManagerFactory() {
	}

	public static ISteerManagerFactory getInstance() {
		if (steerManagerFactory == null) {
			steerManagerFactory = new SteerManagerFactory();
		}
		return steerManagerFactory;
	}

	@Override
	public <T extends ISteerManager> ISteerManager createSteerManager(Class<T> steerManagerClass) throws BehaviourException {
		ISteerManager steerManager = null;
		try {
			Constructor<T> constructor = steerManagerClass.getConstructor();
			steerManager = constructor.newInstance();
		} catch (Exception e) {
			throw new BehaviourException(e);
		}
		steerManager.init();
		return steerManager;
	}
}
